﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using WebApp.Models;

namespace WebApp.Controllers
{
    public class HomeController : Controller
    {
        /// <summary>
        /// adfasfdafa
        /// </summary>
        private readonly ILogger<HomeController> _logger;

        private readonly IDistributedCache _cache;

        public HomeController(ILogger<HomeController> logger, IDistributedCache _cache)
        {
            _logger = logger;
            this._cache = _cache;
        }

        public IActionResult Index()
        {
            string val = HttpContext.Session.GetString("username");
            //session为空写入一条测试数据
            if (string.IsNullOrEmpty(val))
            {
                HttpContext.Session.SetString("username", "jindong");
            }
            HttpContext.Session.SetString("ID", "1fdasfd23");
            ViewBag.sessionid = HttpContext.Session.Id;
            ViewBag.val = HttpContext.Session.GetString("username");
            ViewBag.port = HttpContext.Request.Host.Port;
            ViewBag.Web = Appsettings.app("WebSite", "Name");
            return View();
        }

        public IActionResult IndexOK()
        {
            string val = HttpContext.Session.GetString("username");

            ViewBag.sessionid = HttpContext.Session.Id;
            ViewBag.val = val;
            ViewBag.ID = HttpContext.Session.GetString("ID");
            ViewBag.Web = Appsettings.app("WebSite", "Name");
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}